#include "ipc_service_registry.h"

#include <mutex>

#include <logger.h>

void IpcServiceRegistry::AddService(IIpcService &service)
{
    services.insert({service.GetID(), service});
}

void IpcServiceRegistry::RemoveService(const IIpcService &service)
{
    services.erase(service.GetID());
}

void IpcServiceRegistry::DispatchMessage(IpcMessageParcel &parcel)
{
    LOG2SO(DEBUG)
        << "dispatch way: " << parcel.way
        << ", pid: " << parcel.callingPid
        << ", cid: " << parcel.callingCid
        << ", sid: " << parcel.callingSid
        << ", data: " << parcel.data;
    services.at(parcel.callingSid).Process(parcel);
}
